package com.hiwhitley.easy.day07;

/**
 * Created by hiwhitley on 2016/8/8.
 */
public class ReOrderArrayTest {
    public static void reOrderArray(int[] array) {
        int len = array.length;
        int[] newArray = new int[len];
        int temp = 0;
        for (int i = 0; i < len; i++) {
            if (isOdd(array[i])) {
                newArray[temp] = array[i];
                temp++;
            }
        }

        for (int i = 0; i < len; i++) {
            if (!isOdd(array[i])) {
                newArray[temp] = array[i];
                temp++;
            }
        }

        for (int i = 0; i < len; i++) {
            array[i] = newArray[i];
            System.out.println(array[i]);
        }
    }

    private static boolean isOdd(int num) {
        return (num & 1) == 1;
    }

    public static void main(String[] args) {
        int[] array = new int[]{9, 8, 7, 6, 5, 4, 3};
        reOrderArray(array);
    }
}
